;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
;;; This file is part of rehash.
;;;
;;; rehash is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; rehash is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with rehash.  If not, see <http://www.gnu.org/licenses/>.
(define-library (remirror snakeoil)
  (export %snakeoil-private-key %snakeoil-certificate
	  %snakeoil-credentials)
  (import (only (rnrs base)
		define begin let list)
	  (only (rnrs bytevectors)
		bytevector?)
	  (only (remirror embed-file)
		data-from-builddir)
	  (only (gnutls)
		import-x509-private-key
		import-x509-certificate
		x509-certificate-format/pem
		make-certificate-credentials
		set-certificate-credentials-x509-keys!)
	  (srfi srfi-26))
  (begin
    (define %snakeoil-private-key
      (import-x509-private-key
       (data-from-builddir u8vector "snakeoil-key.pem")
       x509-certificate-format/pem))

    (define %snakeoil-certificate
      (import-x509-certificate
       (data-from-builddir u8vector "snakeoil-cert.pem")
       x509-certificate-format/pem))

    ;; TODO: can we use anonymous credentials instead?
    (define %snakeoil-credentials
      (let ((cred (make-certificate-credentials)))
	(set-certificate-credentials-x509-keys!
	 cred (list %snakeoil-certificate) %snakeoil-private-key)
	cred))))
